#include <iostream>

using namespace std;

bool f(int x)
{
    if (x % 400 == 0) return true;
    if (x % 100 == 0) return false;
    if (x % 4 == 0) return true;
    return false;
}

int main() {
    int y, m;
    scanf("%d %d", &y, &m);
    if (m == 2)
    {
        if (f(y))
            cout << 29 << endl;
        else cout << 28 << endl;
        return 0;
    }
    if (m <= 7)
    {
        if (m % 2 == 1)
            cout << 31 << endl;
        else cout << 30 << endl;
        return 0;
    }
    else
    {
        if (m % 2 == 0)
            cout << 31 << endl;
        else cout << 30 << endl;
        return 0;
    }

    return 0;
}